<template>
	<!-- 确认订单页面 -->
	<view class="content">
		<!-- 订单区域 -->
		<view class="confirmorder">
			<!-- 地址区域 -->
			<view class="addressbar">
				<view class="addreceiver_img">
					<image mode="widthFix" src="http://localhost:3000/img/dingweiorder.png"></image>
				</view>
				<view class="addreceiver_bar">
					<view class="addreceiver_bar_user">
						<text class="addreceiver_bar_user_name">{{user_locations.cgn_name}}</text>
						<text class="addreceiver_bar_user_phone">{{user_locations.cgn_tel}}</text>
					</view>
					<text class="addreceiver_bar_addreceiver">{{user_locations.cgn_address}}</text>
				</view>
				<view class="addreceiver_icon" @click="selectreceiver">
					<image mode="widthFix" src="http://localhost:3000/img/next2.png"></image>
				</view>
			</view>
			<!-- 订单列表区域 -->
			<view class="order">
				<view class="order_list">
					<view class="order_list_img">
						<image mode="widthFix" src="http://localhost:3000/images/shop5.png"></image>
					</view>
					<view class="order_list_content">
						<text class="order_list_content_title">伊利 纯牛奶 </text>
						<text class="order_list_content_miaoshu">礼盒包装24*250ml</text>
						<view class="order_list_price">
							<text class="order_list_price_jg">￥69.9</text>
							<text class="order_list_price_count">x2</text>
						</view>
					</view>
				</view>
				<view class="order_list">
					<view class="order_list_img">
						<image mode="widthFix" src="http://localhost:3000/images/shop5.png"></image>
					</view>
					<view class="order_list_content">
						<text class="order_list_content_title">伊利 纯牛奶 </text>
						<text class="order_list_content_miaoshu">礼盒包装24*250ml</text>
						<view class="order_list_price">
							<text class="order_list_price_jg">￥69.9</text>
							<text class="order_list_price_count">x2</text>
						</view>
					</view>
				</view>
				<view class="order_list">
					<view class="order_list_img">
						<image mode="widthFix" src="http://localhost:3000/images/shop5.png"></image>
					</view>
					<view class="order_list_content">
						<text class="order_list_content_title">伊利 纯牛奶 </text>
						<text class="order_list_content_miaoshu">礼盒包装24*250ml</text>
						<view class="order_list_price">
							<text class="order_list_price_jg">￥69.9</text>
							<text class="order_list_price_count">x2</text>
						</view>
					</view>
				</view>
				<view class="order_list">
					<view class="order_list_img">
						<image mode="widthFix" src="http://localhost:3000/images/shop5.png"></image>
					</view>
					<view class="order_list_content">
						<text class="order_list_content_title">伊利 纯牛奶 </text>
						<text class="order_list_content_miaoshu">礼盒包装24*250ml</text>
						<view class="order_list_price">
							<text class="order_list_price_jg">￥69.9</text>
							<text class="order_list_price_count">x2</text>
						</view>
					</view>
				</view>
			</view>
			<!-- 支付方式 -->
			<view class="payment">
				<text class="payment_left">支付方式</text>
				<view class="payment_right">
					<text class="payment_right_text">在线支付</text>
					<view class="payment_right_img">
						<image mode="widthFix" src="http://localhost:3000/img/zffs.png"></image>
					</view>
				</view>
			</view>
		</view>
		<!-- 合计区域 -->
		<van-submit-bar
		  :price="price"
		  button-text="提交订单"
		  @submit="onSubmit"
		  custom-class="custom-class"
		>
			<text style="color: #999;">共3件，</text>
		</van-submit-bar>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				// 合计
				price:100,
				// 默认地址
				user_locations:{},
				// 收货地址
				cgn_id:''
			}
		},
		onLoad(cgn_id) {
			console.log(cgn_id)
			this.cgn_id=cgn_id.cgn_id
		},
		onShow() {
			uni.getStorage({
				key:"cgn_ids",
				success: (res) => {
					console.log(res,'dddd')
					this.getuserlocations(res.data)
						uni.removeStorage({
							key:"cgn_ids"
						})
				},
				fail:()=> {
					this.getuserlocations_default()
				}
			})
			// if(this.cgn_id){
			// 	this.getuserlocations()
			// }else{
			// 	this.getuserlocations_default()
			// }
		},
		methods:{
			// 获取默认地址
			getuserlocations_default(){
				uni.getStorage({
					key:"user",
					success: (res) => {
						uni.request({
							url:"http://localhost:3001/user_locations_default",
							data:{user_id:JSON.parse(res.data).user_id},
							method:"GET",
							success: (res) => {
								if(res.data.data.length>0){
									this.user_locations=res.data.data[0]
									console.log(res)
								}
							}
						})
					}
				})
				
			},
			// 获取地址
			getuserlocations(res){
				uni.request({
					url:"http://localhost:3001/user_editaddress",
					data:{cgn_id:res},
					method:"GET",
					success: (data) => {
						if(data.data.data.length>0){
							this.user_locations=data.data.data[0]
							
						}
					}
				})
				
			},
			// 选择收货地址
			selectreceiver(){
				uni.navigateTo({
					url:"../mone/selectreceiver?nav=true&user_id="+this.user_locations.user_id
				})
			},
			// 提交订单,进入收银台页面
			onSubmit(price){
				uni.navigateTo({
					url:"./checkstand"
				})
				console.log(price)
			}
		}
	}
</script>

<style>
	.confirmorder{
		padding: 20rpx;
		box-sizing: border-box;
	}
	image{
		width: 100%!important;
		display: block!important;
	}
	.addressbar{
		background-color: #FFFFFF;
		border-radius: 12rpx;
		padding: 36rpx 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.addreceiver_img{
		width: 64rpx;
		margin-right: 18rpx;
	}
	.addreceiver_bar{
		flex: 1;
		display: flex;
		flex-direction: column;
		font-size: 23rpx;
		color: #000000;
		font-weight: 900;
	}
	.addreceiver_bar_user_phone{
		color: #afafaf;
		margin-left: 16rpx;
	}
	.addreceiver_bar_addreceiver{
		margin-right: 10rpx;
		margin-top: 10rpx;
	}
	.addreceiver_icon{
		width: 32rpx;
	}
	
	.order{
		margin: 20rpx 0;
		border-radius: 12rpx;
		background-color: #FFFFFF;
	}
	.order_list{
		padding: 20rpx;
		display: flex;
	}
	.order_list:nth-child(n+2){
		border-top: 2rpx solid #eaeaea;
	}
	.order_list_img{
		width: 170rpx;
		margin-right: 16rpx;
	}
	.order_list_content{
		flex: 1;
		display: flex;
		flex-direction: column;
		font-size: 22rpx;
	}
	.order_list_content_title{
		margin: 10rpx 0;
	}
	.order_list_content_miaoshu{
		color: #999;
		margin-bottom: 10rpx;
	}
	.order_list_price_count{
		color: #999;
		margin-left: 20rpx;
	}
	
	.payment{
		padding: 30rpx 20rpx;
		border-radius: 14rpx;
		background-color: #FFFFFF;
		font-size: 24rpx;
		font-weight: 900;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 100rpx;
	}
	.payment_right{
		display: flex;
	}
	.payment_right_img{
		width: 34rpx;
		margin-left: 10rpx;
	}
	
	/* 根节点样式类 */
	.custom-class{
		width: 750rpx;
		height: 96rpx;
		border-top:2rpx solid #f3f3f3 ;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		font-weight: 900;
		font-size: 24rpx!important;
	}
	.van-submit-bar__bar,.van-submit-bar__price,.van-submit-bar__currency,.van-submit-bar__price-integer{
		font-size: 24rpx!important;
	}
	..van-button__text{
		font-size: 26rpx!important;
	}
	.van-submit-bar__button,.van-button,.van-button--danger,.van-button--normal,.van-button--round{
		width:192rpx!important;
		height: 68rpx!important;
		font-size: 26rpx!important;
	}
</style>
